using System;
using System.Collections.Generic;

namespace Kannon.Core
{
    public abstract class HttpHeaderCollection<T> : NameValueCollection
    {
        private readonly Func<T, string> headerConverter;

        public string this[T header]
        {
            get { return this[headerConverter(header)]; }
            set { this[headerConverter(header)] = value; }
        }

        protected HttpHeaderCollection(Func<T, string> headerConverter) :
            this(headerConverter, new Dictionary<string, string>())
        {
        }

        protected HttpHeaderCollection(Func<T, string> headerConverter, IDictionary<string, string> dictionary) :
            base(dictionary)
        {
            this.headerConverter = headerConverter;
        }

        public void Add(T header, string value)
        {
            Add(headerConverter(header), value);
        }
    }
}